package com.utils.basejava.concurrent.ThreadPool;
/*package com.utils.Thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kyhd.bidder.mq.model.MqModel;
import com.kyhd.bidder.util.AdxConst;
import com.kyhd.bidder.util.InitConst;
import com.utils.math.MathUtil;

import lombok.extern.slf4j.Slf4j;

*//**
 * 异步提交kafka和redis
 * @author XR-8
 *
 *//*
@Service
@Slf4j
public class AsynService {
	
//	@Autowired
//	Producer producer;
	
	@Autowired
	RedisService redisService;
	
//	private static ExecutorService executor = Executors.newFixedThreadPool(5);
	private static ExecutorService executor = Executors.newSingleThreadExecutor();

	public void asynTask(String topic, MqModel message) throws InterruptedException {
		executor.execute(new Process(topic, message));
	}

	
	private class Process implements Runnable {
		
		private String topic;
		private MqModel message;
		
		public Process(String topic, MqModel message) {
			this.topic = topic;
			this.message = message;
		}
		
		@Override
		public void run() {
				//客户千次曝光均价(元)=实际千次曝光均价(元)/(1-盈利比)
				if(StringUtils.isNotBlank(topic)&&message!=null) {
					//发送给kafka
//					producer.sendMessage(topic, message.getJSONObject().toString());
					String date = InitConst.formatYMD();
					Double profitRate = message.getProfitRate();
					if(profitRate==null) 
						profitRate = 0.0;
					
					//发送给redis 
					//key为日期、广告主和单元id等，hashkey为(创意id+竞得价格+盈利比+机器标识)，统计单元下所有创意的消耗数据
					String advcKey = InitConst.getAdvUnitKey(date, topic, message.getAdverId(), message.getUnitId());
					String priceHashKey = "0.0";
					if(InitConst.BID_TOPIC.equals(topic)) {
						priceHashKey = message.getCreativeId()+InitConst.KEY_O+message.getBidfloor()+InitConst.KEY_O+profitRate+InitConst.KEY_O+InitConst.IP;
					}else {
						priceHashKey = message.getCreativeId()+InitConst.KEY_O+message.getWinPrice()+InitConst.KEY_O+profitRate+InitConst.KEY_O+InitConst.IP;
					}
					Object value = redisService.getMapOne(advcKey, priceHashKey);
					String num = "1";
					if(value!=null) {
						num =  (Integer.valueOf(value.toString())+1)+"";
					}
					log.info("unit consume data set key:({}),hashkey:({}),num:{}",advcKey, priceHashKey, num);
					try {
						redisService.putMapOne(advcKey, priceHashKey, num);
					} catch (Exception e) {
						e.printStackTrace();
					}
					
					if(InitConst.PIXEL_TOPIC.equals(topic)) {
						//key为日期和广告主id等，hashkey为(创意id+客户竞得出价的CPM+机器标识)，统计广告主消耗
						Double customerPrice = 0.0;
						if(profitRate==0.0) {
							customerPrice = message.getWinPrice();
						}else {
							customerPrice = MathUtil.div(message.getWinPrice(), MathUtil.sub(1, MathUtil.div(profitRate, 100, 4)), InitConst.ROUND_RATE);
						}
						
						String advConsumeKey = InitConst.getAdvConsumeKey(date, topic, message.getAdverId());
						String customerPriceHashKey = message.getUnitId()+InitConst.KEY_O+customerPrice+InitConst.KEY_O+InitConst.IP;
						Object advValue = redisService.getMapOne(advConsumeKey, customerPriceHashKey);
						String adVnum = "1";
						if(advValue!=null) {
							adVnum =  (Integer.valueOf(advValue.toString())+1)+"";
						}
						log.info("advster consume data set key:({}),hashkey:({}),num:{}",advConsumeKey, customerPriceHashKey, adVnum);
						try {
							redisService.putMapOne(advConsumeKey, customerPriceHashKey, adVnum);
						} catch (Exception e) {
							e.printStackTrace();
						} 
						
						//key为日期和adx平台id等，hashkey为(创意id+实际竞得价+盈利比+机器标识)，统计adx消耗
						Integer adxId = AdxConst.adxMap.get(message.getAdx());
						if(adxId==null)
							adxId=0;
						String adxActConsumeKey = InitConst.getAdxActConsumeKey(date, topic, adxId);
						String adxCreativeHashKey = message.getCreativeId()+InitConst.KEY_O+message.getWinPrice()+InitConst.KEY_O+profitRate+InitConst.KEY_O+InitConst.IP;
						Object adxActValue = redisService.getMapOne(adxActConsumeKey, adxCreativeHashKey);
						String adxCNum = "1";
						if(adxActValue!=null) {
							adxCNum =  (Integer.valueOf(adxActValue.toString())+1)+"";
						}
						log.info("adx consume data set key:({}),hashkey:({}),num:{}",adxActConsumeKey, adxCreativeHashKey, adxCNum);
						try {
							redisService.putMapOne(adxActConsumeKey, adxCreativeHashKey, adxCNum);
						} catch (Exception e) {
							e.printStackTrace();
						} 
					}
				}
			 
		}
	}
	
}
*/